/* $Id: http.h,v 1.3 2006/03/15 03:49:16 jfb Exp $ */
/*
 * Copyright (c) 2003 Jean-Francois Brousseau <phrakt@gmail.com>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */


#ifndef _HTTP_HTTP_H_
#define _HTTP_HTTP_H_

#include <sys/types.h>

#include <limits.h>
#include <stdarg.h>

#include <canopy/log.h>



/* the following definitions apply to this implementation only */
#define HTTP_VERSION_MAJOR    1
#define HTTP_VERSION_MINOR    0


#define HTTP_CRLF   "\r\n"
#define HTTP_LWS    " \t"		/* linear whitespace */
#define HTTP_HDRSEP ':'			/* header name-value separator */


/* default HTTP listening port */
#define HTTP_PORT	80


/* recognized HTTP versions */
enum http_version {
	HTTP_VERSION_09 =  9,		/* HTTP 0.9 */
	HTTP_VERSION_10 = 10,		/* HTTP 1.0 */
	HTTP_VERSION_11 = 11,		/* HTTP 1.1 */
};



/* supported HTTP methods */
enum http_method {
	HTTP_METHOD_INVAL = 0,
	HTTP_METHOD_CONNECT,
	HTTP_METHOD_DELETE,
	HTTP_METHOD_GET,
	HTTP_METHOD_HEAD,
	HTTP_METHOD_OPTIONS,
	HTTP_METHOD_POST,
	HTTP_METHOD_PUT,
	HTTP_METHOD_TRACE,
	HTTP_METHOD_EXT,		/* extension */
};


#define HTTP_TYPE_SIMPLE   1     /* simple type, HTTP/0.9 */
#define HTTP_TYPE_FULL     2



/* date formats */
#define HTTP_DATE_RFC1123  1
#define HTTP_DATE_RFC850   2
#define HTTP_DATE_ANSIC    3
#define HTTP_DATE_DEFAULT  HTTP_DATE_RFC1123


/*
 * Standard typedefs for the HTTP library
 */
typedef struct http_conn          http_conn_t;
typedef struct http_hdr           http_hdr_t;
typedef struct http_msg           http_msg_t;
typedef struct http_req           http_req_t;
typedef struct http_resp          http_resp_t;
typedef struct http_entity        http_ent_t;
typedef struct http_client        http_client_t;
typedef struct http_vhost         http_vhost_t;
typedef struct http_auth_token    http_authtok_t;
typedef struct http_acl           http_acl_t;


extern cnp_log_t  *http_logchan;




int                 http_init    (void);
void                http_cleanup (void);

/* logging system */
int      http_log_sethdlr  (void (*hdlr)(int, const char *));

#endif /* _HTTP_HTTP_H_ */
